ADD_SUBDIRECTORY (boot)
ADD_SUBDIRECTORY (ucos_port)

FILE (GLOB THIS_DIR_SRC "*.c" "*.h" "*.cx")

IF ("1" STREQUAL "${BUILD_FROM_SRC}")
SET (SOURCE_FILES ${HC12_CHIP_FILE} ${SOURCE_FILES} ${THIS_DIR_SRC} PARENT_SCOPE)
ELSE ("1" STREQUAL "${BUILD_FROM_SRC}")
SET (SOURCE_FILES ${SOURCE_FILES} ${THIS_DIR_SRC} PARENT_SCOPE)
ENDIF ("1" STREQUAL "${BUILD_FROM_SRC}")

SET (INCUDE_DIRS  ${INCUDE_DIRS} ${HC12_INCLUDE_DIR} ${CMAKE_CURRENT_LIST_DIR} PARENT_SCOPE)


IF (NOT EXISTS ${PROJECT_BINARY_DIR}/TBDML.ini)
FILE (COPY
    ${CMAKE_CURRENT_LIST_DIR}/hiwave/TBDML.ini
    ${CMAKE_CURRENT_LIST_DIR}/hiwave/Simulation.ini
    ${CMAKE_CURRENT_LIST_DIR}/hiwave/C_Layout.hwl
    ${CMAKE_CURRENT_LIST_DIR}/hiwave/TBDML_Erase_unsecure_hcs12xe.cmd
    ${CMAKE_CURRENT_LIST_DIR}/hiwave/postload.cmd
    DESTINATION ${PROJECT_BINARY_DIR}
)
ENDIF(NOT EXISTS ${PROJECT_BINARY_DIR}/TBDML.ini)

ADD_CUSTOM_TARGET (
    tbdml
    COMMAND ${HC12_PATH}/hiwave.exe -Prod=${PROJECT_BINARY_DIR}/TBDML.ini -cmd="RESET" ${TARGET_ELF}
)
ADD_CUSTOM_TARGET (
    sim
    COMMAND ${HC12_PATH}/hiwave.exe -Prod=${PROJECT_BINARY_DIR}/Simulation.ini -cmd="RESET" ${TARGET_ELF}
)
